<?php

namespace App\Imports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;

class BaseImport implements ToCollection
{
    public $count = 0;
    public $errorMessage = null;
    public $data;
    public $source;

    /**
     * @param $source
     */
    public function __construct()
    {
    }


    /**
     * @param Collection $collection
     */
    public function collection(Collection $collection)
    {
        $headerRow = $collection->shift();
        $data = [];
        foreach ($collection as $item) {
            $row = [];
            foreach ($headerRow as $index => $value) {
                $row[$value] = $item->get($index);
            }
            $data[] = $row;
        }
        $this->data = $data;
    }
}
